package com.ls.server.controller;

import com.ls.server.dto.DictCategoryDTO;
import com.ls.server.dto.DictQueryDTO;
import com.ls.server.service.DictCategoryService;
import com.ls.server.vo.DictCategoryVO;
import com.ls.server.vo.PageResult;
import com.ls.server.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典大类控制器
 */
@RestController
@RequestMapping("/dict/category")
public class DictCategoryController {

    private final DictCategoryService dictCategoryService;

    public DictCategoryController(DictCategoryService dictCategoryService) {
        this.dictCategoryService = dictCategoryService;
    }

    /**
     * 分页查询字典大类
     * @param queryDTO 查询条件
     * @return 分页结果
     */
    @PostMapping("/page")
    public Result<PageResult<DictCategoryVO>> page(@RequestBody DictQueryDTO queryDTO) {
        return Result.success(dictCategoryService.page(queryDTO));
    }

    /**
     * 查询所有字典大类
     * @return 字典大类列表
     */
    @GetMapping("/list")
    public Result<List<DictCategoryVO>> list() {
        return Result.success(dictCategoryService.listByVO());
    }

    /**
     * 根据ID查询字典大类
     * @param id 字典大类ID
     * @return 字典大类
     */
    @GetMapping("/get/{id}")
    public Result<DictCategoryVO> getById(@PathVariable Long id) {
        return Result.success(dictCategoryService.getById(id));
    }

    /**
     * 新增字典大类
     * @param dto 字典大类信息
     * @return 操作结果
     */
    @PostMapping
    public Result<Boolean> save(@RequestBody DictCategoryDTO dto) {
        return Result.success(dictCategoryService.save(dto));
    }

    /**
     * 修改字典大类
     * @param dto 字典大类信息
     * @return 操作结果
     */
    @PutMapping
    public Result<Boolean> update(@RequestBody DictCategoryDTO dto) {
        return Result.success(dictCategoryService.update(dto));
    }

    /**
     * 删除字典大类
     * @param id 字典大类ID
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(dictCategoryService.delete(id));
    }
}
